<?php
class Task_type extends MY_Controller
{	
	function __construct() {
		parent::__construct();
	}

	function index(){
		$this->load->model("Task_types");
		$data = $this->user_post_data;
		$pid = $data['pid'];
		$conditions['status'] = 1;
		$conditions['pid'] = $pid;
		$task_types = $this->Task_types->get_task_category_list(0,0,$conditions);
		/*$task_type_list = array('count' => 0, 'list' => array());
		if(!empty($task_types['count'])){
			$task_type_list['count'] = $task_types['count'];
			foreach ($task_types['list'] as $key => $value) {
				$task_type_list['list'][$value['pid']][] = $value;
			}
		}*/
		echo json_encode(array("code" => 200, "data" => $task_types));
	}

	//获取顶级分类
	function get_top_task_type(){
		$this->load->model("Task_types");
		$data = $this->user_post_data;
		$conditions['status'] = 1;
		$task_types = $this->Task_types->get_task_category_list(0, 0, $conditions);
		$task_type_list = array('count' => 0, 'list' => array());
		if(!empty($task_types['count'])){
			foreach ($task_types['list'] as $key => $value) {
				if($value['pid'] == 0){
					$task_type_list['count'] += 1;
					$task_type_list['list'][$value['id']]['info'] = $value;
				}else{
					$task_type_list['list'][$value['pid']]['sub'][] = $value;
				}
			}
		}
		echo json_encode(array("code" => 200, "data" => $task_type_list));
	}

	function get_task_type_list(){
		$this->load->model("Task_types");
		$conditions['status'] = 1;
		$task_types = $this->Task_types->get_task_category_list(0, 0, $conditions);
		if(!empty($task_types['count'])){
			$task_type_list = array();
			foreach ($task_types['list'] as $key => $value) {
				if($value['pid'] == 0){
					$task_type_list[$value['id']]['info'] = $value;
				}else{
					$task_type_list[$value['pid']]['list'][] = $value;
				}
			}
			$task_types['list'] = $task_type_list;
		}
		echo json_encode(array("code" => 1, "data" => $task_types));
	}

	function search_task_type(){
		$data = $this->user_post_data;
		if(empty(trim($data['task_type_name']))){
			echo json_encode(array("code" => 0, "msg" => '搜索内容为空'));
			exit;
		}
		$this->load->model("Task_types");
		$conditions['name'] = trim($data['task_type_name']);
		$task_types = $this->Task_types->get_task_category_list(0, 0, $conditions);
		echo json_encode(array("code" => 1, "data" => $task_types));
	}
}